#include "timesumfilter.h"

TimeSumFilter::TimeSumFilter()
{
}

TimeSumFilter::TimeSumFilter(int maxMs)
{
    m_maxMs = maxMs;
}

TimeSumFilter::~TimeSumFilter()
{
}

void TimeSumFilter::SetMaxMs(int maxMs)
{
    m_maxMs = maxMs;
}

bool TimeSumFilter::Add(int ms, float v)
{
    m_ms += ms;
    m_count += 1;
    m_sum += v;

    if(m_ms >= m_maxMs)
    {
        m_val = m_sum / m_count;

        Reset();
        return true;
    }

    return false;
}

float TimeSumFilter::GetValue()
{
    return m_val;
}

void TimeSumFilter::Reset()
{
    m_ms = 0;
    m_count = 0;
    m_sum = 0;
}
